﻿#include "EditorMeshMaterialPropertyViewModel.h"
#include "Mesh/StaticMesh.h"
#include "Material/Material.h"
#include "Project/ProjectModel.h"


void REditorMeshMaterialPropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel, TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{
    Super::BindModel(InModel, InAbilityViewModel);

    StaticMeshModel=InModel;
}

int64_t REditorMeshMaterialPropertyViewModel::GetMaterialSlotNum()
{
    return StaticMeshModel->GetMesh()->DefaultMaterials.Num();
}

TSharedObjectPtr<RTexture2D> REditorMeshMaterialPropertyViewModel::GetMaterialThumbnail(int64_t InIndex)
{
    return TSharedObjectPtr<RTexture2D>();
}

CString REditorMeshMaterialPropertyViewModel::GetMaterialName(int64_t InIndex)
{
    auto Material = StaticMeshModel->GetMesh()->DefaultMaterials[InIndex];
    if (Material)
    {
        return Material->GetNodeName();
    }
    return U"未设置材质";
}

void REditorMeshMaterialPropertyViewModel::SelectAsset(
    TSharedObjectPtr<RMaterial> InMaterial
    ,int64_t InMaterialSlotIndex
    )
{
    StaticMeshModel->SetMaterial(InMaterialSlotIndex,InMaterial);
}
